package com.wangdao.wechatmall.util;

import com.wangdao.wechatmall.bean.vo.admin.BaseRespVo;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.List;

/**
 * @author ShuiYi
 * @time 2021-07-14 10:17
 */
@Component
public class ValidatedUtils {
    public static BaseRespVo validate(BindingResult result) {
        FieldError fieldErrors = result.getFieldError();
        String field = fieldErrors.getField();
        Object rejectedValue = fieldErrors.getRejectedValue();
        String defaultMessage = fieldErrors.getDefaultMessage();

        return BaseRespVo.fail("请求参数：" + field + "不合法；因为你传入了一个" + rejectedValue +"; " + defaultMessage);

    }
}
